//
//  MSDetailContactsTableVC.m
//  SocietySale
//
//  Created by Mike on 16/11/8.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSDetailContactsTableVC.h"

@interface MSDetailContactsTableVC ()
//section头部标题
@property(nonatomic,copy)NSArray *sectionTitleArray;
//项目信息数据
@property(nonatomic,copy)NSArray *proprietorArray;
//项目动态数据
@property(nonatomic,copy)NSArray *designArray;

@end

@implementation MSDetailContactsTableVC

- (void)viewDidLoad{
    [super viewDidLoad];
    
    self.sectionTitleArray = @[@"业主",@"设计",@"施工"];
}

- (void)setContactArray:(NSArray *)contactArray{
    _contactArray = contactArray;
    self.proprietorArray = _contactArray[0];
    self.designArray = _contactArray[1];
    [self.tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    if (section == 0) {//
//        return _proprietorArray.count;
//    }
//    else if(section == 1){//
//        return _designArray.count;
//    }
    return [_contactArray[section] count];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellId = @"cellId";
    MSDetailContactsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[MSDetailContactsCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.delegate = (id)self.delegate;
    cell.model = _contactArray[indexPath.section][indexPath.row];//
    if (indexPath.row == [_contactArray[indexPath.section] count]-1){
        cell.bgView.hidden = YES;
    }
    else{
        cell.bgView.hidden = NO;
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == [_contactArray[indexPath.section] count]-1) {
        return [MSDetailContactsCell cellHeightWithModel:_contactArray[indexPath.section][indexPath.row]];
    }
    else{
        return [MSDetailContactsCell cellHeightWithModel:_contactArray[indexPath.section][indexPath.row]]+8;
    }

    return [MSDetailContactsCell cellHeightWithModel:_contactArray[indexPath.row]];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 40)];
    bgView.backgroundColor = kDefaultViewBackgroundColor;
    
    UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(0, 12.5, 10, 15)];
    blueView.backgroundColor = kBlueColor;
    [bgView addSubview:blueView];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(22, 0, 150, 40)];
    titleLabel.text = self.sectionTitleArray[section];
    titleLabel.textColor = kDarkGrayColor;
    titleLabel.font = HeitiFont(14);
    [bgView addSubview:titleLabel];

    return bgView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.5;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *horizonLineView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.5)];
    horizonLineView.backgroundColor = kNormalGray;
    return horizonLineView;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    if ([self.delegate respondsToSelector:@selector(scrollViewWillBeginDragging:)]) {
        [self.delegate performSelector:@selector(scrollViewWillBeginDragging:) withObject:self];
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
@end
